﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace EnheimGallery.DAL.ElementsCRUDDAL
{
    public class PhotoInfoData
    {
        public string Name;
        public string Description;
    }
    public static class PhotosDAL
    {
        public static Photo CreatePhoto(string name, int categoryId, string description = "")
        {
            Photo newPhoto = new Photo()
            {
                PhotoName = name,
                AddedDate = DateTime.Now,
                LastSeen = DateTime.Now,
                Description = description,
                CategoryId = categoryId,
            };
            return newPhoto;
        }

        public static void CreatePhotoForUser(aspnet_Users user, Photo photo)
        {
            EnheimGalleryEntities db = new EnheimGalleryEntities();
            db.AddToPhotos(photo);
            db.SaveChanges();
            // here add the image file to the application filesystem
        }
        public static PhotoInfoData ReadPhotoInfo(Photo photo)
        {
            PhotoInfoData info = new PhotoInfoData();
            info.Name = photo.PhotoName;
            info.Description = photo.Description;
            return info;
        }
        public static void UpdatePhoto(Photo photo, string name, string description)
        {
            EnheimGalleryEntities db = new EnheimGalleryEntities();
            Photo modifiedPhoto = photo;
            modifiedPhoto.PhotoName = name;
            modifiedPhoto.Description = description;
            db.DeleteObject(photo);
            db.AddToPhotos(modifiedPhoto);
            db.SaveChanges();
        }

        public static void DeletePhoto(Photo photo)
        {
            EnheimGalleryEntities db = new EnheimGalleryEntities();
            db.DeleteObject(photo);
            //also delete from filesystem
        }
    }
}
